/** 
 * Copyright 2014 whj All Rights Reserved.
 * 项目名：codegnrt
 * 包名：com.whj.code.comment
 * 文件名：WhjCommentGenerator.java 
 * 日期：2016-01-26 10:21
 */
package com.whj.code.comment;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.InnerClass;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.internal.DefaultCommentGenerator;

/**
 * whj生成备注类.
 * @author wanghj
 *
 */
public class WhjCommentGenerator extends DefaultCommentGenerator{
    private boolean suppressAllComments;

    public WhjCommentGenerator() {
        super();
        suppressAllComments = false;
    }
    
    @Override
    public void addFieldComment(Field field,
            IntrospectedTable introspectedTable,
            IntrospectedColumn introspectedColumn) {
        StringBuffer sb = new StringBuffer();

        field.addJavaDocLine("/**"); 
        sb.append(" * ").append(introspectedColumn.getRemarks()).append(".");
        field.addJavaDocLine(sb.toString());
        field.addJavaDocLine(" */"); 
    }

    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
    }

    @Override
    public void addGetterComment(Method method,
            IntrospectedTable introspectedTable,
            IntrospectedColumn introspectedColumn) {
    }

    @Override
    public void addSetterComment(Method method,
            IntrospectedTable introspectedTable,
            IntrospectedColumn introspectedColumn) {
    }

    @Override
    public void addClassComment(InnerClass innerClass,
            IntrospectedTable introspectedTable) {

        StringBuilder sb = new StringBuilder();

        innerClass.addJavaDocLine("/**"); //$NON-NLS-1$

        sb.append(" * 表： "); //$NON-NLS-1$
        sb.append(introspectedTable.getFullyQualifiedTable());
        sb.append(" 的映射类").append(".");

        innerClass.addJavaDocLine(sb.toString());

        innerClass.addJavaDocLine(" * @author wanghaijun");
        innerClass.addJavaDocLine(" */"); //$NON-NLS-1$
    }

    @Override
    public void addGeneralMethodComment(Method method,
            IntrospectedTable introspectedTable) {
        if (suppressAllComments) {
            return;
        }

        StringBuilder sb = new StringBuilder();

        method.addJavaDocLine("/**"); //$NON-NLS-1$

        sb.append(" * ").append(method.getName()).append(" from table ")
            .append(introspectedTable.getFullyQualifiedTable()).append(".");
        method.addJavaDocLine(sb.toString());

        method.addJavaDocLine(" */"); //$NON-NLS-1$
    }

    @Override
    public void addComment(XmlElement xmlElement) {

    }
}
